#!/usr/bin/env bash
set -eo pipefail

project=$1
appName=$2
imgName=$3


# bash build-docker-image.sh mp-gateway  mp-gateway  amy:8082/java/mp-gateway-java:2024

if [ -z "$imgName" ]; then
  echo "构建镜像,参数: 项目路径  应用名  镜像名:版本"
  exit 1;
fi

SCRIPTDIR=$(cd $(dirname "${BASH_SOURCE[0]}") >/dev/null && pwd)
cd $SCRIPTDIR

cd ../../
rm -rf ./$project/build-jar

mkdir -p ./$project/target/lib
mkdir -p ./$project/build-jar/target-jar  ./$project/build-jar/target-lib


cp -f mp-business/src/main/resources/devops/java/java.dockerfile   $project/build-jar/Dockerfile
cp -f mp-business/src/main/resources/devops/shell/start-java.sh    $project/build-jar/target-jar

cd $project/build-jar

cp -f  ../target/lib/*    target-lib
cp -f  ../target/*.jar    target-jar
cp -f  ../target/*.txt    target-jar

sed -i 's|@dockerImage@|amy:5000/tools/openjdk:17|ig' Dockerfile
sed -i 's|@java-opts@||ig' Dockerfile
sed -i 's|@java-args@||ig' Dockerfile
sed -i 's|@namespace@|default|ig' Dockerfile
sed -i 's|@profiles@||ig' Dockerfile
sed -i 's|code/@folder@/||ig' Dockerfile
sed -i "s|@appName@|$appName|ig" Dockerfile

docker build  -t  $imgName   .


docker push  $imgName